package com.ailk.kbi.kbirazor.component
{
	import flash.events.Event;
	
	import mx.core.IVisualElement;
	
	import spark.components.HGroup;
	
	/**
	 * 节点的一行，包含KpiBox或Label。
	 * 
	 * 
	 */
	public class NodeRow extends HGroup
	{
		public function NodeRow()
		{
			super();
		}
		
		override public function addElementAt(element:IVisualElement, index:int):IVisualElement{
			element.addEventListener("widthChanged", widthChangedHandler);
			element.addEventListener("heightChanged", heightChangedHandler);
			return super.addElementAt(element, index);
		}
		
		private function widthChangedHandler(event:Event):void {
			var newWidth:Number = (this.numElements - 1) * this.gap;
			for(var index:int = 0; index < this.numElements; index++){
				var element:IVisualElement = this.getElementAt(index);
				newWidth = newWidth + element.width;
			}
			this.width = newWidth;
		}
		
		private function heightChangedHandler(event:Event):void {
			var newHeigth:Number = 0;
			for(var index:int = 0; index < this.numElements; index++){
				var element:IVisualElement = this.getElementAt(index);
				newHeigth = Math.max(newHeigth, element.height);
			}
			this.height = newHeigth;
		}
	}
}